<?php

namespace Admin\Controller;

use Think\Controller;

class PublicController extends Controller {

    /**
     * 登录页面
     */
    public function login() {
        service('Passport')->isLogin() && redirect(U('Index/index')); //如果已登录，则跳转至管理页面的首页
        $this->display();
    }

    /**
     * 登录页面提交
     */
    public function doLogin() {
        $post = I('post.');
        $res = service('Passport')->login($name, $passwd);
        if ($res === false) {
            $this->error('登录失败');
        } else {
            $this->success('登录成功');
        }
    }

    /**
     * 退出登录
     */
    public function logout() {
        service('Passport')->logout();
        $this->assign('jumpUrl', U('Public/login'));
        $this->success('退出成功');
    }

}
